package com.gopay.webtest.controller.cbrmb;

import java.io.IOException;
import java.util.Map;

import javax.annotation.Resource;

import com.gopay.webtest.controller.base.BaseController;
import org.apache.log4j.Logger;
import org.dom4j.DocumentException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.gopay.webtest.handler.Trans7040Handler;
import com.gopay.webtest.vo.ImportInfo;
import com.gopay.webtest.xml.XmlDao;

/**
 * 
 * @ClassName: CbRmbReturnController 
 * @Description: webtest退货 
 * @author gd.cui
 * @date 2016年7月22日 上午10:52:37 ww.gopay.com.cn Inc.All rights reserved.
 */
@Controller
@RequestMapping("/cbrmb")
public class CbRmbReturnController extends BaseController {

    private static Logger logger = Logger.getLogger(CbRmbReturnController.class);

    @Resource(name = "xmlDao")
    private XmlDao xmlDao = null;
    @Resource(name = "trans7040Handler")
    private Trans7040Handler trans7040Handler;

    @RequestMapping(method = RequestMethod.GET, value = "/return")
    public ModelAndView returnCbrmb() {

        ModelAndView mv = new ModelAndView("gopay.webtest.pay.return_cbrmb");

        // 加载xml数据到
        try {
            Map<String, String> map = this.xmlDao.readData4Map("cbrmbreturn", "cbrmbreturninfo");
            mv.addObject("cbrmbreturninfo", map);
            mv.setViewName("gopay.webtest.pay.return_cbrmb");
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return mv;

    }

    @RequestMapping("/return/submit")
    public ModelAndView addReturnCbrmb(ImportInfo importInfo) {

        ModelAndView mv = new ModelAndView("gopay.webtest.pay.return_cbrmb_submit");

        /*** 对表单数据进行处理 begin */

        try {
            // 进行加签
            trans7040Handler.sign(importInfo.getTranCode(), "signType", "signValue", importInfo, getRequest());
        } catch (Exception e) {

            logger.error("加签出错");
            e.printStackTrace();
        }
        mv.setViewName("gopay.webtest.pay.return_cbrmb_submit");
        mv.addObject("importInfo", importInfo);
        return mv;
    }

}
